package org.lmind.example.common.web;

import java.net.URL;
import java.util.List;
import java.util.regex.Pattern;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

public class DefaultSiteNavigation implements SiteNavigation {

	public DefaultSiteNavigation() {
		
	}

	@Override
	public SiteNode getRootNode() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public SiteNode getNodeFromUrl(URL url) {
		// TODO Auto-generated method stub
		return null;
	}

	
	@XmlRootElement(name="navigation")
	@XmlAccessorType(XmlAccessType.NONE)
	public static class SiteConfiguration {
		
		private List<SiteConfigurationNode> nodes;

		
		@XmlElement(name="node")
		public List<SiteConfigurationNode> getNodes() {
			return nodes;
		}

		public void setNodes(List<SiteConfigurationNode> nodes) {
			this.nodes = nodes;
		}
		
	}
	
	
	public static class SiteConfigurationNode {
		
		private String defaultPage;
		
		private String title;
		
		private Pattern pattern;
		
		private List<SiteConfigurationNode> nodes;

		@XmlAttribute
		public String getDefaultPage() {
			return defaultPage;
		}

		public void setDefaultPage(String defaultPage) {
			this.defaultPage = defaultPage;
		}

		@XmlAttribute
		public String getTitle() {
			return title;
		}

		public void setTitle(String title) {
			this.title = title;
		}

		@XmlElement
		public String getPattern() {
			return pattern == null ? null : pattern.pattern();
		}

		public void setPattern(String pattern) {
			this.pattern = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
		}

		@XmlElement
		public List<SiteConfigurationNode> getNodes() {
			return nodes;
		}

		public void setNodes(List<SiteConfigurationNode> nodes) {
			this.nodes = nodes;
		}
	}
}
